//package cn.iocoder.yudao.module.vote.controller.admin.voteuserresult;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.extra.servlet.ServletUtil;
//import cn.iocoder.yudao.framework.common.pojo.CommonResult;
//import cn.iocoder.yudao.framework.common.pojo.PageResult;
//import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
//import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
//import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
//import cn.iocoder.yudao.module.vote.aop.SubmitCheck;
//import cn.iocoder.yudao.module.vote.constants.RedisConst;
//import cn.iocoder.yudao.module.vote.controller.admin.voteinfo.vo.OnlineVoteParamsVO;
//import cn.iocoder.yudao.module.vote.controller.admin.voteinfo.vo.VoteInfoPageReqVO;
//import cn.iocoder.yudao.module.vote.controller.admin.voteinfo.vo.VoteInfoRespVO;
//import cn.iocoder.yudao.module.vote.controller.admin.voterecorddetail.vo.VoteRecordDetailExportReqVO;
//import cn.iocoder.yudao.module.vote.controller.admin.voteuserresult.vo.*;
//import cn.iocoder.yudao.module.vote.convert.voteinfo.VoteInfoConvert;
//import cn.iocoder.yudao.module.vote.convert.voteuserresult.VoteUserResultConvert;
//import cn.iocoder.yudao.module.vote.dal.dataobject.userref.VoteUserRefDO;
//import cn.iocoder.yudao.module.vote.dal.dataobject.voteinfo.VoteInfoDO;
//import cn.iocoder.yudao.module.vote.dal.dataobject.voterecorddetail.VoteRecordDetailDO;
//import cn.iocoder.yudao.module.vote.dal.dataobject.voteuserresult.VoteUserResultDO;
//import cn.iocoder.yudao.module.vote.dal.dataobject.voteuserresultdetail.VoteUserResultDetailDO;
//import cn.iocoder.yudao.module.vote.service.userref.VoteUserRefService;
//import cn.iocoder.yudao.module.vote.service.voteinfo.VoteInfoService;
//import cn.iocoder.yudao.module.vote.service.voterecord.VoteRecordService;
//import cn.iocoder.yudao.module.vote.service.voterecorddetail.VoteRecordDetailService;
//import cn.iocoder.yudao.module.vote.service.voteuserresult.VoteUserResultService;
//import cn.iocoder.yudao.module.vote.service.voteuserresultdetail.VoteUserResultDetailService;
//import cn.iocoder.yudao.module.vote.utils.AesUtil;
//import cn.iocoder.yudao.module.vote.utils.RedisService;
//import cn.iocoder.yudao.module.vote.utils.VoteStatusUtils;
//import com.alibaba.fastjson.JSONObject;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.validation.Valid;
//import java.io.IOException;
//import java.util.List;
//import java.util.concurrent.TimeUnit;
//
//import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
//import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
//import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
//import static cn.iocoder.yudao.module.vote.constants.RedisConst.ONLINE_VOTED_USERRESULT;
//import static cn.iocoder.yudao.module.vote.constants.RedisConst.ONLINE_VOTED_USERRESULT_EXPIRE;
//import static cn.iocoder.yudao.module.vote.enums.ErrorCodeConstants.*;
//
//@Api(tags = "管理后台 - 年度投票结果")
//@RestController
//@RequestMapping("/voteyear/online")
//@Validated
//public class VoteYearOnlineController {
//
//    @Resource
//    private VoteUserResultService userResultService;
//    @Resource
//    private VoteInfoService voteInfoService;
//    @Resource
//    private VoteRecordService voteRecordService;
//    @Resource
//    private VoteRecordDetailService detailService;
//    @Resource
//    private RedisService redisService;
//
//
//    @SubmitCheck(value="submitVoteyearOnlineResult",expireSeconds=10)
//    @PostMapping("/updateResult")
////    @ApiOperation("更新投票结果")
//    public CommonResult<Boolean> updateH5Result(@Valid @RequestBody VoteOnlineUpdateReqVO onlineUpdateReqVO,@RequestParam String data, HttpServletRequest request) {
////        try {
//            OnlineVoteParamsVO paramsVO = JSONObject.parseObject(AesUtil.decrypt(data), OnlineVoteParamsVO.class);
//            onlineUpdateReqVO.setIsMamager(paramsVO.getIsManager());
//            onlineUpdateReqVO.setIsDept(paramsVO.getIsDept());
//            onlineUpdateReqVO.setVoteId(paramsVO.getVoteId());
//
//            String ip = ServletUtil.getClientIP(request, null);
//            onlineUpdateReqVO.setIp(ip);
//            userResultService.updateOnlineResult(onlineUpdateReqVO);
//
//            return success(true);
////        }catch (Exception e){
////            exception(ONLINE_ENCRYPT_PARAMS_ERROR);
////        }
////        return error(ONLINE_ENCRYPT_PARAMS_ERROR);
//    }
//
//
//    @GetMapping("/list")
//    @ApiOperation("获得投票结果列表")
//    public CommonResult<List<VoteYearUserResultCateRespVO>> getUserResultList(@RequestParam String data,HttpServletRequest request) {
//
//        try{
//            OnlineVoteParamsVO paramsVO = JSONObject.parseObject(AesUtil.decrypt(data),OnlineVoteParamsVO.class);
//
//            VoteInfoDO voteInfoDO = redisService.getCacheObject(StrUtil.format(RedisConst.VOTE_INFO,paramsVO.getVoteId()));
//            if(voteInfoDO==null){
//                voteInfoDO = voteInfoService.getInfo(paramsVO.getVoteId());
//            }
//            String ip = ServletUtil.getClientIP(request, null);
//            if(voteInfoDO==null){
//                exception(INFO_NOT_EXISTS);
//            }
//            if(!voteInfoDO.getIsPush()){
//                exception(INFO_TIME_NOTSTART);
//            }
//            if (voteRecordService.isVote(voteInfoDO.getId(), ip)) {
//                exception(INFO_USER_HAS_VOTED);
//            }
//            List<VoteYearUserResultCateRespVO> list = userResultService.getH5VoteList(paramsVO);
//            return success(list);
//        }catch (Exception e){
//            return error(ONLINE_ENCRYPT_PARAMS_ERROR);
//        }
//    }
//
//    public static void main(String[] args) {
//        String data = "4950D4DC2AF93A846449BD1B0C2BD0342B18308A6BA50851E3AC33610A4D40BCC922783A0DF071662DE564F6AFA50F32";
//        OnlineVoteParamsVO paramsVO = JSONObject.parseObject(AesUtil.decrypt(data),OnlineVoteParamsVO.class);
//        System.out.println(JSONObject.toJSONString(paramsVO));
//    }
//
//
//    @PostMapping("/votedList")
////    @ApiOperation("获得投票结果列表")
//    public CommonResult<List<VoteYearUserResultCateRespVO>> votedList(@RequestBody VoteRecordDetailExportReqVO reqVO,@RequestParam String data,HttpServletRequest request) {
//
//
//        OnlineVoteParamsVO paramsVO = JSONObject.parseObject(AesUtil.decrypt(data),OnlineVoteParamsVO.class);
//
//        VoteInfoDO voteInfoDO =voteInfoService.getInfo(paramsVO.getVoteId());
//        if(voteInfoDO==null){
//            exception(INFO_NOT_EXISTS);
//        }
//
//        List<VoteYearUserResultCateRespVO> list = userResultService.getH5VoteList(paramsVO);
//        String ip = ServletUtil.getClientIP(request, null);
//        reqVO.setIp(ip);
//        reqVO.setVoteId(paramsVO.getVoteId());
//
//        List<VoteRecordDetailDO> recordDetailDOList = detailService.getRecordDetailList(reqVO);
//
//        if(CollUtil.isEmpty(recordDetailDOList)){
//            return success(list);
//        }
//
//        for(VoteRecordDetailDO detailDO:recordDetailDOList){
//            for(VoteYearUserResultCateRespVO cateRespVO:list){
//                for(VoteYearUserResultCateSubRespVO subRespVO:cateRespVO.getSubList()){
//                    if(detailDO.getUserName().equals(subRespVO.getUserName())){
//                        Integer voteResult = VoteStatusUtils.switchVoteStatus(detailDO);
//                        subRespVO.setVoteStatus(voteResult);
//                    }
//                }
//            }
//        }
//        return success(list);
//    }
//
//
//    @GetMapping("/userIsVote")
//    @ApiOperation("是否已投票")
//    public CommonResult<Boolean> userIsVote(@RequestParam("data")String data,HttpServletRequest request) {
//        try{
//            OnlineVoteParamsVO paramsVO = JSONObject.parseObject(AesUtil.decrypt(data),OnlineVoteParamsVO.class);
//
//            String ip = ServletUtil.getClientIP(request, null);
//            return success(voteRecordService.isVote(paramsVO.getVoteId(),ip));
//        }catch (Exception e){
//            return error(ONLINE_ENCRYPT_PARAMS_ERROR);
//        }
//    }
//
//
//}
